home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Whack-A-Bill / source code / score.h < prev    next >
Text File  |  1997-09-24  |  4KB  |  213 lines

  1. void updateScores(long PlayerOneScore,long PlayerTwoScore);
  2. void SetupScores(void);
  3. void DrawCurrent(int theNumber, Rect theRect);
  4.  
  5. Boolean scoresSetup=false;
  6. PicHandle zero,
  7.           one,
  8.           two,
  9.           three,
  10.           four,
  11.           five,
  12.           six,
  13.           seven,
  14.           eight,
  15.           nine;
  16. typedef struct score
  17.     {
  18.     Rect One,
  19.          Ten,
  20.          Hundred,
  21.          Thousand,
  22.          TenThousand,
  23.          HundredThousand;
  24.     }score;
  25. score PlayerOneScoreStruct,
  26.       PlayerTwoScoreStruct;
  27.  
  28. void updateScores(long PlayerOneScore,long PlayerTwoScore)
  29. {
  30. WindowPtr oldPort;
  31.  
  32. int count;
  33. long scoreBuffer;
  34.  
  35.  
  36. if (!(scoresSetup))
  37.     SetupScores();
  38.  
  39. GetPort(&oldPort);
  40. SetPort(gMainWindow);
  41.  
  42.  
  43. //---------------PlayerOne--------------
  44. scoreBuffer=PlayerOneScore;
  45. count=0;
  46. while (scoreBuffer>99999)
  47.     {
  48.     count++;
  49.     scoreBuffer=(scoreBuffer-100000);
  50.     }
  51. DrawCurrent(count,PlayerOneScoreStruct.HundredThousand);
  52. count=0;
  53. while (scoreBuffer>9999)
  54.     {
  55.     count++;
  56.     scoreBuffer=(scoreBuffer-10000);
  57.     }
  58. DrawCurrent(count,PlayerOneScoreStruct.TenThousand);
  59.  
  60. count=0;
  61. while (scoreBuffer>999)
  62.     {
  63.     count++;
  64.     scoreBuffer=(scoreBuffer-1000);
  65.     }
  66. DrawCurrent(count,PlayerOneScoreStruct.Thousand);
  67. count=0;
  68. while (scoreBuffer>99)
  69.     {
  70.     count++;
  71.     scoreBuffer=(scoreBuffer-100);
  72.     }
  73. DrawCurrent(count,PlayerOneScoreStruct.Hundred);
  74. count=0;
  75. while (scoreBuffer>9)
  76.     {
  77.     count++;
  78.     scoreBuffer=(scoreBuffer-10);
  79.     }
  80. DrawCurrent(count,PlayerOneScoreStruct.Ten);
  81. count=0;
  82. while (scoreBuffer>0)
  83.     {
  84.     count++;
  85.     scoreBuffer=(scoreBuffer-1);
  86.     }
  87. DrawCurrent(count,PlayerOneScoreStruct.One);
  88.     
  89. //---------------PlayerTwo--------------
  90. scoreBuffer=PlayerTwoScore;
  91. count=0;
  92. while (scoreBuffer>99999)
  93.     {
  94.     count++;
  95.     scoreBuffer=(scoreBuffer-100000);
  96.     }
  97. DrawCurrent(count,PlayerTwoScoreStruct.HundredThousand);
  98. count=0;
  99. while (scoreBuffer>9999)
  100.     {
  101.     count++;
  102.     scoreBuffer=(scoreBuffer-10000);
  103.     }
  104. DrawCurrent(count,PlayerTwoScoreStruct.TenThousand);
  105.  
  106. count=0;
  107. while (scoreBuffer>999)
  108.     {
  109.     count++;
  110.     scoreBuffer=(scoreBuffer-1000);
  111.     }
  112. DrawCurrent(count,PlayerTwoScoreStruct.Thousand);
  113. count=0;
  114. while (scoreBuffer>99)
  115.     {
  116.     count++;
  117.     scoreBuffer=(scoreBuffer-100);
  118.     }
  119. DrawCurrent(count,PlayerTwoScoreStruct.Hundred);
  120. count=0;
  121. while (scoreBuffer>9)
  122.     {
  123.     count++;
  124.     scoreBuffer=(scoreBuffer-10);
  125.     }
  126. DrawCurrent(count,PlayerTwoScoreStruct.Ten);
  127. count=0;
  128. while (scoreBuffer>0)
  129.     {
  130.     count++;
  131.     scoreBuffer=(scoreBuffer-1);
  132.     }
  133. DrawCurrent(count,PlayerTwoScoreStruct.One);
  134.  
  135. SetPort(oldPort);
  136. }
  137.  
  138. void DrawCurrent(int theNumber, Rect theRect)
  139. {
  140. switch (theNumber)
  141.     {
  142.     case 0:
  143.         DrawPicture(zero,&theRect);
  144.         break;
  145.     case 1:
  146.         DrawPicture(one,&theRect);
  147.         break;
  148.     case 2:
  149.         DrawPicture(two,&theRect);
  150.         break;
  151.     case 3:
  152.         DrawPicture(three,&theRect);
  153.         break;
  154.     case 4:
  155.         DrawPicture(four,&theRect);
  156.         break;
  157.     case 5:
  158.         DrawPicture(five,&theRect);
  159.         break;
  160.     case 6:
  161.             DrawPicture(six,&theRect);
  162.         break;
  163.     case 7:
  164.         DrawPicture(seven,&theRect);
  165.         break;
  166.     case 8:
  167.         DrawPicture(eight,&theRect);
  168.         break;
  169.     case 9:
  170.         DrawPicture(nine,&theRect);
  171.         break;
  172.     }
  173. }
  174.  
  175. void SetupScores(void)
  176. {
  177. PicHandle One,
  178.      Ten,
  179.      Hundred,
  180.      Thousand,
  181.      TenThousand,
  182.      HundredThousand;
  183.          
  184. SetRect(&PlayerOneScoreStruct.HundredThousand,540,177,553,202);
  185. SetRect(&PlayerOneScoreStruct.TenThousand,553,177,566,202);
  186. SetRect(&PlayerOneScoreStruct.Thousand,566,177,579,202);
  187. SetRect(&PlayerOneScoreStruct.Hundred,579,177,592,202);
  188. SetRect(&PlayerOneScoreStruct.Ten,592,177,605,202);
  189. SetRect(&PlayerOneScoreStruct.One,605,177,618,202);
  190.  
  191. SetRect(&PlayerTwoScoreStruct.HundredThousand,540,311,553,336);
  192. SetRect(&PlayerTwoScoreStruct.TenThousand,553,311,566,336);
  193. SetRect(&PlayerTwoScoreStruct.Thousand,566,311,579,336);
  194. SetRect(&PlayerTwoScoreStruct.Hundred,579,311,592,336);
  195. SetRect(&PlayerTwoScoreStruct.Ten,592,311,605,336);
  196. SetRect(&PlayerTwoScoreStruct.One,605,311,618,336);
  197.  
  198. if (playerOne.score==5)
  199.     SysBeep(1);
  200.  
  201. zero=GetPicture(1200);
  202. one=GetPicture(1201);
  203. two=GetPicture(1202);
  204. three=GetPicture(1203);
  205. four=GetPicture(1204);
  206. five=GetPicture(1205);
  207. six=GetPicture(1206);
  208. seven=GetPicture(1207);
  209. eight=GetPicture(1208);
  210. nine=GetPicture(1209);
  211.  
  212. scoresSetup=true;
  213. }